#!/bin/bash
set -e
# set -x

# 生成版本号 如 1.2.3
if [ -z "$1" ]; then
    echo "请输入版本号 如 1.2.3"
    exit 1
fi
version=$1

if [ -z "$2" ]; then
    echo "请输入环境,如test或prod,默认test"
fi
environment=${2:-test}

# 获取 Major Minor Patch
major=$(echo $version | cut -d. -f1)
minor=$(echo $version | cut -d. -f2)
patch=$(echo $version | cut -d. -f3)

echo "major: $major"
echo "minor: $minor"
echo "patch: $patch"

# 打包前端
# 根据环境选择打包命令
if [ "$environment" == "prod" ]; then
    yarn build:prod
else
    yarn build:test
fi

# 推送
docker build --platform=linux/amd64 -t $version .
docker push $version
